<template>
  <div>
    <el-table
      :data="tableData"
      style="width: 100%; margin-bottom: 20px"
      height="480"
      row-key="permissionId"
      border
    >
      <el-table-column prop="fixId" label="维修编号" sortable></el-table-column>
      <el-table-column prop="faultId" label="故障编号" sortable></el-table-column>
      <el-table-column prop="fixStartTime" label="维修开始时间" sortable></el-table-column>
      <el-table-column prop="fixEndTime" label="维修结束时间" sortable></el-table-column>
      <el-table-column prop="empId" label="维修人员id" sortable></el-table-column>

      <el-table-column label="操作" fixed="right">
        <template slot-scope="scope">
          <!-- <el-button type="primary" size="mini">分配</el-button> -->
          <!-- <el-button type="info" @click="updateUI(scope.row)" size="mini"
            >修改 -->
          <!-- </el-button> -->
          <el-button type="danger" @click="del(scope.row)" size="mini">删除</el-button>
        </template>
      </el-table-column>


    </el-table>

     

     <el-dialog title="故障" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="故障状态" :label-width="formLabelWidth">
          <el-input v-model="form.faultStatus" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="saveOrUpdate()">确 定</el-button>
      </div>
    </el-dialog>


     <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageInfo.page"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="pageInfo.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageInfo.total">
    </el-pagination>
  </div>
</template>

<script>

import {findAll,doSaveOrUpdate,dodel} from '@/api/fix'

export default {
  mounted(){
    this.updateTable();
  },
  data(){
    return{
      form:{},
      tableData:[],
      pageInfo: {
        total: 0,
        page: 1,
        size: 5,
      },
      dialogFormVisible: false,
      formLabelWidth: '180px',
    }
  },
  methods:{
    updateUI(row){
      this.dialogFormVisible = true;
      this.form = row;
    },
    del(row){
      this.$confirm('确认删除?')
          .then(() => {
            dodel(row.fixId).then(r=>{
              if (r.code == 200) {
                this.updateTable();
                this.$message.success(r.msg);
                return;
              }
              this.$message.error(r.msg);
            });
          })
          .catch(() => {
          });

    },
    handleSizeChange(size) {
      this.pageInfo.size = size;
      this.updateTable();
    },
    handleCurrentChange(page) {
      this.pageInfo.page = page;
      this.updateTable();
    },
    updateTable(){
      findAll(this.pageInfo).then(r=>{
        this.tableData=r.data.list;
        this.pageInfo.total=r.data.total;
      })
    },
    saveOrUpdate(){
      doSaveOrUpdate(this.form).then(r=>{
        if(r.code == 200){
          this.dialogFormVisible = false;
          this.$message.success(r.msg);
          this.updateTable();
          this.fileList=[]
        }
      })
    },
  }
};
</script>

<style>
</style>